package com.web.service.category;

import com.web.bean.category.Category;
import com.web.dao.category.CategoryDao;
import com.web.dao.category.CategoryDaoImpl;
import com.web.dao.novel.NovelDaoImpl;
import com.web.utils.DBUtil;

import java.sql.Connection;
import java.util.List;

/**
 * @autor Chen
 * @create 2021--25-14:13
 * @desc
 */
public class CategoryServiceImpl implements CategoryService{
    @Override
    public List<Category> selectCategory() throws Exception {
        DBUtil dbUtil = DBUtil.getInstance();
        Connection connection = dbUtil.getConnection();
        CategoryDao categoryDao = new CategoryDaoImpl(connection);
        List<Category> categories = categoryDao.selectCategories();
        dbUtil.close();
        return categories;
    }

    @Override
    public Category selectByCode(String code) throws Exception {

        return null;
    }

    @Override
    public void addCategory(Category category) throws Exception {
        DBUtil dbUtil = DBUtil.getInstance();
        Connection connection=dbUtil.getConnection();
        CategoryDaoImpl categoryDao=new CategoryDaoImpl(connection);
        categoryDao.addCategory(category);
        dbUtil.close();

    }

    @Override
    public void deleteCategory(String code) throws Exception {
        DBUtil dbUtil = DBUtil.getInstance();
        Connection connection=dbUtil.getConnection();
        CategoryDaoImpl categoryDao=new CategoryDaoImpl((connection));
        categoryDao.deleteCategory(code);
        dbUtil.close();

    }
}
